from django.shortcuts import render,get_object_or_404
from django.http import  HttpResponse,HttpResponseRedirect
from .models import  Quesion, Choice, Item, ItemCount
from django.template import loader
from django.db import models


def get_items_info(item_id):
    """

    :param item_id:
    :return: a dict { 'dates':[2016-08-23,2016-08-24], 'times':[1,0]}
    """
    item = get_object_or_404(Item,pk=item_id)
    recs = item.itemcount_set.all()
    res_dict = {}
    tuples = []
    for i in recs:
        tuples.append((i.pub_date,i.count))
    res_dict['date2count'] = tuples

    return res_dict
